@extends('home.base.main')
@section('content')
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>购物车页面</title>

<link href="{{ asset('AmazeUI-2.4.2/assets/css/amazeui.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('basic/css/demo.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('css/cartstyle.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ asset('css/optstyle.css') }}" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="{{ asset('js/jquery.js') }}"></script>
<script type='text/javascript' src="/js/jquery-1.8.3.min.js"></script>
<!--购物车-->
<div class="concent">
	<div id="cartTable">
		<div class="cart-table-th">
			<div class="wp">
				<div class="th th-chk">
					<div id="J_SelectAll1" class="select-all J_SelectAll"></div>
				</div>
				<div class="th th-item">
					<div class="td-inner">商品信息</div>
				</div>
				<div class="th th-price">
					<div class="td-inner">单价</div>
				</div>
				<div class="th th-amount">
					<div class="td-inner">数量</div>
				</div>
				<div class="th th-sum">
					<div class="td-inner">金额</div>
				</div>
				<div class="th th-op">
					<div class="td-inner">操作</div>
				</div>
			</div>
		</div>
		<div class="clear"></div>
		<tr class="item-list">
			<div class="bundle  bundle-last ">				
				<div class="clear"></div>
				<div class="bundle-main">					
					@foreach($list as $k => $v)
					<ul class="item-content clearfix">
						<li class="td td-chk">
							<div class="cart-checkbox ">
								<input class="check" id="J_CheckBox_170037950254" name="items[]" value="170037950254" type="checkbox">
								<label for="J_CheckBox_170037950254"></label>
							</div>
						</li>
						<li class="td td-item">
							<div class="item-pic">
								<a href="#" target="_blank" data-title="美康粉黛醉美东方唇膏口红正品 持久保湿滋润防水不掉色护唇彩妆" class="J_MakePoint" data-point="tbcart.8.12">
									<img src="{{ asset('admin/upload').'/'.$v->pic }}" class="itempic J_ItemImg" width="80" height="80"></a>
							</div>
							<div class="item-info">
								<div class="item-basic-info">
									<a href="#" target="_blank" title="美康粉黛醉美唇膏 持久保湿滋润防水不掉色" class="item-title J_MakePoint" data-point="tbcart.8.11">{{ $price[$k]->title }}</a>
								</div>
							</div>
						</li>
						<li class="td td-info">
							<div class="item-props">
								<span class="sku-line">颜色：12#川南玛瑙</span>
								<span class="sku-line">包装：裸装</span>
								<!-- <span tabindex="0" class="btn-edit-sku theme-login">修改</span> -->
								<i class="theme-login am-icon-sort-desc"></i>
							</div>
						</li>
						<li class="td td-price" name="lilili">
							<div class="item-price price-promo-promo">
								<div class="price-content">									
									<div class="price-line">
										<em name="emem" class="J_Price price-now" tabindex="0">{{ $price[$k]->price }}</em>
									</div>
								</div>
							</div>
						</li>
						<li class="abc td td-amount" name="lili">
							<div class="amount-wrapper ">
								<div class="item-amount ">
									<div class="sl">
										<input class="am-btn" onclick="domin(this)" type="button" value="-">										
										<input class="text_box" type="text" value="{{ $v->amount }}" style="width:30px;">
										<input id="doadd" class="am-btn" onclick="doadd(this)" type="button" value="+">
									</div>
								</div>
							</div>
						</li>
						<li class="td td-sum">
							<div class="td-inner">
								<em tabindex="0" id="sum" name="xiaoji" class="J_ItemSum number">{{ $v->money }}</em>
							</div>
						</li>
						<li class="td td-op">
							<form id="delete">
								{{ csrf_field() }}
								{{ method_field('DELETE') }}
								<div class="td-inner">
									<a title="移入收藏夹" class="btn-fav" href="{{ url('home/collect').'/'.$v->id }}">移入收藏夹</a>
									<a href="javascript:onclick(dodelete({{ $v->id }}))" data-point-url="#" class="delete">删除</a>									
								</div>
							</form>
							<script type="text/javascript">
								function dodelete(obj){									
									var myformb = document.getElementById('delete');
									myformb.method = 'post';
									myformb.action = '/home/doPay/'+obj;
									myformb.submit();
								}
							</script>
						</li>
					</ul>					
					@endforeach
				</div>				
			</div>
		</tr>		
		<div class="clear"></div>
		<script>
			//计算总计
			function zongji(){
				var em = $('em[name="xiaoji"]');
				var zj = 0 ;
				for(var i=0;i<em.length;i++){

					zj+=parseInt($(em[i]).html());
				}
				
				$('.price-sum').find('em').html(zj);
			}
			//计算总件
			function zongjian(){
				var em = $('.text_box');
				var zj = 0;
				for(var i=0;i<em.length;i++){

					zj+=parseInt($(em[i]).val());
				}
				$('#J_SelectedItemsCount').html(zj);

			}
			function domin(obj){
				var num = $(obj).next('input').val();
				num--;
				if(num > 0){
					$(obj).next('input').val(num);

					var numm = parseInt(num);
					var price = parseInt($(obj).parent().parent().parent().parent().prev().find('em[name="emem"]').html());

					var xiaoj = parseInt(numm*price);
					
					$(obj).parent().parent().parent().parent().next().find('em[name="xiaoji"]').html(parseInt(xiaoj));

					zongji();
					zongjian();								
				}
			}

			function doadd(obj){
				var num = $(obj).prev('input').val();
				num++;
				if(num > 0){
					$(obj).prev('input').val(num);
					$(obj).next('input').val(num);
					var numm = parseInt(num);
					var price = parseInt($(obj).parent().parent().parent().parent().prev().find('em[name="emem"]').html());

					var xiaoj = parseInt(numm*price);
					
					$(obj).parent().parent().parent().parent().next().find('em[name="xiaoji"]').html(parseInt(xiaoj));

					zongji();
					zongjian();
				}
			}
		</script>	
	</div>
	<div class="clear"></div>
	<div class="float-bar-wrapper">
		<div id="J_SelectAll2" class="select-all J_SelectAll">
			<div class="cart-checkbox">
				<input class="check-all check" id="J_SelectAllCbx2" name="select-all" value="true" type="checkbox">
				<label for="J_SelectAllCbx2"></label>
			</div>
			<span>全选</span>
		</div>
		<div class="operations">			
			<a href="" hidefocus="true" class="deleteAll">删除</a>
			<a href="#" hidefocus="true" class="J_BatchFav">移入收藏夹</a>			
		</div>
		<div class="float-bar-right">
			<div class="amount-sum">
				<span class="txt">已选商品</span>
				<em id="J_SelectedItemsCount">0</em><span class="txt">件</span>
				<div class="arrow-box">
					<span class="selected-items-arrow"></span>
					<span class="arrow"></span>
				</div>
			</div>
			<div class="price-sum">
				<span class="txt">合计:</span>
				<strong class="price">¥<em id="sumb" >0.00</em></strong>
			</div>
			<div class="btn-area">
				<form id="jiesuan">
					<a href="javascript:onclick(dopay())" id="J_Go" class="submit-btn submit-btn-disabled" aria-label="请注意如果没有选择宝贝，将无法结算">
						<span>结&nbsp;算</span></a>
					<input type="hidden" name="amount" value="" id="zongshu">
					<input type="hidden" name="money" value="" id="money">
					<input type="hidden" name="list" value="" id="list">
				</form>				
			</div>
			<script type="text/javascript">
				function dopay(){										
					var myform = document.getElementById('jiesuan');
					document.getElementById('money').value = document.getElementById('sumb').innerHTML;
					document.getElementById('zongshu').value = document.getElementById('J_SelectedItemsCount').innerHTML;
					myform.action = "{{ url('home/pay').'/'.$price[$k]->id }}";	
					myform.method = 'get';
					myform.submit();
				}				
			</script>
		</div>
	</div>
</div>
<script>
	zongji();
	zongjian();
</script>
@endsection